HA$PBExportHeader$u_cst_gridmain.sru
forward
global type u_cst_gridmain from userobject
end type
type dw_2 from datawindow within u_cst_gridmain
end type
type st_por from statictext within u_cst_gridmain
end type
type dw_1 from u_dw within u_cst_gridmain
end type
type st_categoryname from statictext within u_cst_gridmain
end type
type ddlb_1 from dropdownlistbox within u_cst_gridmain
end type
type st_split from statictext within u_cst_gridmain
end type
type dw_findoutput from datawindow within u_cst_gridmain
end type
type pb_close from picture within u_cst_gridmain
end type
type pb_prev from picture within u_cst_gridmain
end type
type pb_next from picture within u_cst_gridmain
end type
type st_1 from statictext within u_cst_gridmain
end type
type st_find from statictext within u_cst_gridmain
end type
type sle_text from singlelineedit within u_cst_gridmain
end type
type cbx_matchcase from checkbox within u_cst_gridmain
end type
type st_findback from statictext within u_cst_gridmain
end type
type cbx_output from checkbox within u_cst_gridmain
end type
type r_1 from rectangle within u_cst_gridmain
end type
type printdlg from structure within u_cst_gridmain
end type
type devmode from structure within u_cst_gridmain
end type
type devnames from structure within u_cst_gridmain
end type
end forward

type printdlg from structure
	long		lstructsize
	long		hwndowner
	long		hdevmode
	long		hdevnames
	long		hdc
	long		flags
	integer		nfrompage
	integer		ntopage
	integer		nminpage
	integer		nmaxpage
	integer		ncopies
	long		hinstance
	long		lcustdata
	long		lpfnprinthook
	long		lpfnsetuphook
	long		lpprinttemplatename
	long		lpsetuptemplatename
	long		hprinttemplate
	long		hsetuptemplate
end type

type devmode from structure
	character		dmDeviceName[32]
	integer		dmSpecVersion
	integer		dmDriverVersion
	integer		dmSize
	integer		dmDriverExtra
	long		dmFields
	integer		dmOrientation
	integer		dmPaperSize
	integer		dmPaperLength
	integer		dmPaperWidth
	integer		dmScale
	integer		dmCopies
	integer		dmDefaultSource
	integer		dmPrintQuality
	integer		dmColor
	integer		dmDuplex
	integer		dmYResolution
	integer		dmTTOption
	integer		dmCollate
	character		dmFormName[32]
	integer		dmLogPixels
	long		dmBitsPerPel
	long		dmPelsWidth
	long		dmPelsHeight
	long		dmDisplayFlags
	long		dmDisplayFrequency
	long		dmICMMethod
	long		dmICMIntent
	long		dmMediaType
	long		dmDitherType
	long		dmReserved1
	long		dmReserved2
end type

type devnames from structure
	integer		wDriverOffset
	integer		wDeviceOffset
	integer		wOutputOffset
	integer		wDefault
end type

global type u_cst_gridmain from userobject
integer width = 3287
integer height = 2832
long backcolor = 8421376
event resize pbm_size
event rightclicked ( )
event mousemove ( )
event ue_timer pbm_timer
event ue_refrescar ( )
dw_2 dw_2
st_por st_por
dw_1 dw_1
st_categoryname st_categoryname
ddlb_1 ddlb_1
st_split st_split
dw_findoutput dw_findoutput
pb_close pb_close
pb_prev pb_prev
pb_next pb_next
st_1 st_1
st_find st_find
sle_text sle_text
cbx_matchcase cbx_matchcase
st_findback st_findback
cbx_output cbx_output
r_1 r_1
end type
global u_cst_gridmain u_cst_gridmain

type prototypes
PRIVATE:
//General
FUNCTION Long CreateWindowEx(Long dwExStyle, String lpClassName, String lpWindowName, Long dwStyle, Long lx, Long ly, Long nWidth, Long nHeight, Long hWndParent, Long hMenu, Long hInstance, Long lpParam)  Library "USER32.dll" Alias For "CreateWindowExA;Ansi"
FUNCTION Long DestroyWindow(Long wHandle) Library "USER32.dll"
FUNCTION Long GetSystemDirectory (Ref String lp_buffer, Long uSize) Library "Kernel32.dll" Alias FOR "GetSystemDirectoryA;Ansi"
FUNCTION Long LoadLibrary(String lpLibFileName) Library "Kernel32" ALIAS FOR "LoadLibraryA;Ansi"
FUNCTION Long SendMessageString (Long hWnd, Long msg, Long wp, REF String lp) Library "USER32.dll" Alias For "SendMessageA;Ansi"
FUNCTION Long SetWindowPos(Long hWnd, Long m, Long left, Long top, Long nwidth, Long nheight, Long flags) Library "USER32.dll"
Function ULong SetCapture(ulong hWnd) Library "USER32.DLL"
Function Boolean ReleaseCapture() Library "USER32.DLL"

//Print Dialog
FUNCTION Long PrintDlgA(REF PRINTDLG PrintDlg) library "comdlg32.dll" alias for "PrintDlgA;Ansi"
FUNCTION Long GetDevMode(REF DEVMODE Destination, Long Source, Long Size) Library "kernel32.dll" Alias For "RtlMoveMemory;Ansi"
FUNCTION Long GetDevNames(REF DEVNAMES Destination, Long Source, Long Size) Library "kernel32.dll" Alias For "RtlMoveMemory;Ansi"
FUNCTION Long LocalLock(Long Handle) library "kernel32.dll"
FUNCTION Long LocalUnlock(Long Handle) library "kernel32.dll"
//timer
Function Long SetTimer(Long hwnd, Long IdTimer, Long uTimeOut, Long tmpre) Library "user32.dll" 
Function Long KillTimer(Long hwnd, Long IdEvent) Library "user32.dll"


end prototypes

type variables
//PRIVATE:
//General
Long il_SCI
Long il_margincolor = RGB(255,255,255)
String is_border = 'none'
String is_file,is_columna,isa_columna[]
CONSTANT Integer UNITIALIZED = -32000
Integer ii_prevpositionx = UNITIALIZED
Integer ii_prevpositiony = UNITIALIZED
Long il_barcolor=78682240
Long il_barmovecolor=8421504
Window iw_parent
boolean ib_mostrar
u_cst_powerdock iou_powerdock
userobject iuo_user[ ]
s_parm istr_parm
datastore ids_datastore
u_cst_grillamain iuo_grillamain
//Scintilla
CONSTANT Long STYLE_DEFAULT = 32
CONSTANT Long STYLE_LINENUMBER = 33
CONSTANT Long SCI_INSERTTEXT = 2003
CONSTANT Long SCI_GETCURRENTPOS = 2008
CONSTANT Long SCI_SELECTALL = 2013
CONSTANT Long SCI_SETSAVEPOINT = 2014
CONSTANT Long SCI_GOTOLINE = 2024
CONSTANT Long SCI_SETTABWIDTH = 2036
CONSTANT Long SCI_SETMARGINWIDTHN = 2242
CONSTANT Long SCI_STYLESETFORE = 2051
CONSTANT Long SCI_STYLESETBACK = 2052
CONSTANT Long SCI_STYLESETBOLD = 2053
CONSTANT Long SCI_STYLESETITALIC = 2054
CONSTANT Long SCI_STYLESETSIZE = 2055
CONSTANT Long SCI_STYLESETFONT = 2056
CONSTANT Long SCI_SETSELFORE = 2067
CONSTANT Long SCI_SETSELBACK = 2068
CONSTANT Long SCI_GETCOLUMN = 2129
CONSTANT Long SCI_SETSELECTIONSTART = 2142
CONSTANT Long SCI_GETSELECTIONSTART = 2143
CONSTANT Long SCI_SETSELECTIONEND = 2144
CONSTANT Long SCI_GETSELECTIONEND = 2145
CONSTANT Long SCI_GETMODIFY = 2159
CONSTANT Long SCI_GETSELTEXT = 2161
CONSTANT Long SCI_LINEFROMPOSITION = 2166
CONSTANT Long SCI_SCROLLCARET = 2169
CONSTANT Long SCI_REPLACESEL = 2170
CONSTANT Long SCI_UNDO = 2176
CONSTANT Long SCI_CUT = 2177
CONSTANT Long SCI_COPY = 2178
CONSTANT Long SCI_PASTE = 2179
CONSTANT Long SCI_SETTEXT = 2181
CONSTANT Long SCI_GETTEXT = 2182
CONSTANT Long SCI_GETTEXTLENGTH = 2183
CONSTANT Long SCI_SETKEYWORDS = 4005
CONSTANT Long SCI_SETLEXERLANGUAGE = 4006
CONSTANT Long SCI_LINELENGTH = 2350
CONSTANT Long SCI_GETLINE = 2153
CONSTANT Long SCI_SETCURRENTPOS = 2141

//Find
CONSTANT Long SCFIND_WHOLEWORD = 2
CONSTANT Long SCFIND_MATCHCASE = 4
CONSTANT Long SCI_SETTARGETSTART = 2190
CONSTANT Long SCI_SETTARGETEND = 2192
CONSTANT Long SCI_SEARCHINTARGET = 2197
CONSTANT Long SCI_SETSEARCHFLAGS = 2198

//CPP Variables
CONSTANT Long SCE_C_COMMENT = 1
CONSTANT Long SCE_C_COMMENTLINE = 2
CONSTANT Long SCE_C_NUMBER = 4
CONSTANT Long SCE_C_WORD = 5
CONSTANT Long SCE_C_STRING = 6
CONSTANT Long SCE_C_CHARACTER = 7
CONSTANT Long SCE_C_STRINGEOL = 12
CONSTANT Long SCE_C_WORD2 = 16

//Print Dialog
CONSTANT Long PD_PAGENUMS = 2
CONSTANT Long PD_NOSELECTION = 4
CONSTANT Long PD_COLLATE = 16
CONSTANT Long PD_PRINTTOFILE = 32
Long il_frompage = 1
Long il_topage = 1
Long il_flags = PD_NOSELECTION
Long il_copies = 1


end variables

forward prototypes
public function integer of_setcolorcomments (long al_color)
public function integer of_setcolorkeywords (long al_color)
public function integer of_setcolorstring (long al_color)
public function integer of_setfont (string as_font)
public function integer of_setlanguage (string as_language)
public function integer of_settext (string as_text)
public function integer of_setcolorselected (long al_color)
public function string of_gettext ()
public function integer of_setkeywords (string as_keywords)
public function string of_getselectedtext ()
public function integer of_undo ()
public function integer of_copy ()
public function integer of_cut ()
public function integer of_paste ()
public function integer of_setfocus ()
public function boolean of_ismodified ()
public function integer of_setnotmodified ()
public function integer of_setcolormargin (long al_color)
public function integer of_selectall ()
public function integer of_replaceselectedtext (string as_text)
public function integer of_gotoline (long al_line)
public function long of_getcurrentcolumn ()
public function long of_getcurrentline ()
public function integer of_setcolornumber (long al_color)
public function integer of_inserttext (string as_text)
public function string of_getkeywords ()
public function string of_getdatatypes ()
public function integer of_setcolordatatypes (long al_color)
public function integer of_setcoloropenstring (long al_color)
public function integer of_setdatatypes (string as_datatypes)
public function integer of_setborderstyle (string as_border)
public function integer of_settabwidth (integer ai_tabwidth)
public function integer of_resize (integer al_width, integer al_height)
public function integer of_setfontsize (integer ai_size)
public function integer of_setfontbold (boolean ab_bold)
public function integer of_setfontitalic (boolean ab_italic)
public function integer of_showlinenumbers (boolean ab_show)
public function integer of_saveas ()
public function integer of_saveas (string as_file)
public function integer of_save ()
public function integer of_printpreview (string as_title, boolean ab_preview)
public function integer of_print (string as_title)
public function integer of_print ()
public function integer of_printpreview (boolean ab_preview)
public function boolean of_printdialog ()
public function integer of_print (boolean ab_dialog)
public function integer of_print (string as_title, boolean ab_dialog)
private function integer of_bitwiseand (long al_value1, long al_value2)
private function boolean of_getbit (long al_decimal, integer ai_bit)
private function string of_replace (string as_source, string as_old, string as_new)
public function integer of_find ()
private function integer of_bitwiseor (long al_value1, long al_value2)
public function window of_getparentwindow ()
public function string of_gettextatline (long al_line)
public function long of_getlinefromposition (long ll_position)
public function integer of_setcursorposition (long ll_position)
public function integer of_goto ()
private function integer of_find (boolean ab_switch)
private function integer of_findnext (string as_text, long al_start, long al_end, long al_flag)
private function integer of_goto (boolean ab_switch)
public function integer of_open ()
public function integer of_open (string as_file)
public subroutine of_cargar_columnas (datawindow adw)
public subroutine of_filtrar (string cadena, string columna)
public function integer of_getwindow ()
public function integer of_getid ()
public subroutine of_resize ()
end prototypes

event resize;//Resize Scintilla Editor Control
of_Resize(newwidth, newheight)
//dw_1.width=newwidth
//dw_2.width=newwidth
//dw_2.height =newheight - ( st_findback.height + dw_1.height)

end event

event ue_timer;//MessageBox("Atencion","Ya se cumpli$$HEX2$$f3002000$$ENDHEX$$el tiempo del timer")
//dw_1.retrieve();
//commit;
//
end event

public function integer of_setcolorcomments (long al_color);Send(il_SCI, SCI_STYLESETFORE,SCE_C_COMMENT,al_color)
Send(il_SCI, SCI_STYLESETFORE,SCE_C_COMMENTLINE,al_color)

RETURN 1
end function

public function integer of_setcolorkeywords (long al_color);RETURN Send(il_SCI, SCI_STYLESETFORE,SCE_C_WORD,al_color)
end function

public function integer of_setcolorstring (long al_color);Send(il_SCI, SCI_STYLESETFORE,SCE_C_CHARACTER,al_color)
Send(il_SCI, SCI_STYLESETFORE,SCE_C_STRING,al_color)

RETURN 1
end function

public function integer of_setfont (string as_font);RETURN SendMessageString(il_SCI, SCI_STYLESETFONT, STYLE_DEFAULT,as_font)
end function

public function integer of_setlanguage (string as_language);RETURN SendMessageString(il_SCI, SCI_SETLEXERLANGUAGE,0, as_language)
end function

public function integer of_settext (string as_text);SendMessageString(il_SCI, SCI_SETTEXT, Len(as_text), as_text)

of_SetNotModified()

RETURN 1
end function

public function integer of_setcolorselected (long al_color);Send(il_SCI, SCI_SETSELFORE, 1, RGB(255,255,255))
RETURN Send(il_SCI, SCI_SETSELBACK, 1, al_color)
end function

public function string of_gettext ();String ls_text
Long ll_length

ll_length = Send(il_SCI, SCI_GETTEXTLENGTH, 0, 0) + 1
ls_text = Space(ll_length)

SendMessageString(il_SCI, SCI_GETTEXT, ll_length, ls_text)

RETURN ls_text

end function

public function integer of_setkeywords (string as_keywords);RETURN SendMessageString(il_SCI, SCI_SETKEYWORDS,0,as_keywords)
end function

public function string of_getselectedtext ();String ls_text
Long ll_length

ll_length = Send(il_SCI, SCI_GETSELECTIONEND, 0, 0) - Send(il_SCI, SCI_GETSELECTIONSTART, 0, 0)
ls_text = Space(ll_length)

SendMessageString(il_SCI, SCI_GETSELTEXT, ll_length, ls_text)

RETURN ls_text
end function

public function integer of_undo ();RETURN Send(il_SCI, SCI_UNDO, 0, 0)
end function

public function integer of_copy ();RETURN Send(il_SCI, SCI_COPY, 0, 0)
end function

public function integer of_cut ();RETURN Send(il_SCI, SCI_CUT, 0, 0)
end function

public function integer of_paste ();RETURN Send(il_SCI, SCI_PASTE, 0, 0)
end function

public function integer of_setfocus ();IF dw_1.Visible THEN
	dw_1.SetFocus()
ELSE
	//Windows Message - lbuttondown
	Send(il_SCI, 513, 1000, 1000)
	//Windows Message - lbuttonup
	Send(il_SCI, 514, 1000, 1000)
END IF

RETURN 1
end function

public function boolean of_ismodified ();IF Send(il_SCI, SCI_GETMODIFY, 0, 0) <= 0 THEN
	RETURN FALSE
ELSE
	RETURN TRUE
END IF
end function

public function integer of_setnotmodified ();RETURN Send(il_SCI, SCI_SETSAVEPOINT, 0, 0)
end function

public function integer of_setcolormargin (long al_color);il_margincolor = al_color
RETURN Send(il_SCI, SCI_STYLESETBACK, STYLE_LINENUMBER, al_color)
end function

public function integer of_selectall ();RETURN Send(il_SCI, SCI_SELECTALL, 0, 0)
end function

public function integer of_replaceselectedtext (string as_text);RETURN SendMessageString(il_SCI, SCI_REPLACESEL, 0, as_text)

end function

public function integer of_gotoline (long al_line);of_SetFocus()

RETURN Send(il_SCI, SCI_GOTOLINE, al_line - 1, 0)
end function

public function long of_getcurrentcolumn ();Long caretPos

caretPos = Send(il_SCI, SCI_GETCURRENTPOS, 0, 0)

RETURN Send(il_SCI, SCI_GETCOLUMN, caretPos, 0) + 1

end function

public function long of_getcurrentline ();Long caretPos

caretPos = Send(il_SCI, SCI_GETCURRENTPOS, 0, 0)

RETURN Send(il_SCI, SCI_LINEFROMPOSITION, caretPos, 0) + 1

end function

public function integer of_setcolornumber (long al_color);RETURN Send(il_SCI, SCI_STYLESETFORE,SCE_C_NUMBER,al_color)
end function

public function integer of_inserttext (string as_text);RETURN SendMessageString(il_SCI, SCI_INSERTTEXT, -1, as_text)

end function

public function string of_getkeywords ();RETURN 'alias and autoinstantiate call case catch choose close commit connect ' + &
'constant continue create cursor declare delete describe descriptor destroy ' + &
'disconnect do dynamic else elseif end enumerated event execute exit ' + &
'external false fetch finally first for forward from function global goto ' + &
'halt if immediate indirect insert into intrinsic is last library loop next ' + &
'not of on open or parent post prepare prior private privateread privatewrite ' + &
'procedure protected protectedread protectedwrite prototypes public readonly ' + &
'ref return rollback rpcfunc select selectblob shared static step subroutine ' + &
'super system systemread systemwrite then this throw throws to trigger true try ' + &
'type until update updateblob using variables while with within _debug '
end function

public function string of_getdatatypes ();RETURN 'blob longlong boolean long char character real date string datetime ' + &
'time decimal dec unsignedinteger unsignedint uint double unsignedlong ' + &
'ulong integer int '
end function

public function integer of_setcolordatatypes (long al_color);RETURN Send(il_SCI, SCI_STYLESETFORE,SCE_C_WORD2,al_color)
end function

public function integer of_setcoloropenstring (long al_color);RETURN Send(il_SCI, SCI_STYLESETFORE,SCE_C_STRINGEOL,al_color)
end function

public function integer of_setdatatypes (string as_datatypes);RETURN SendMessageString(il_SCI, SCI_SETKEYWORDS,1,as_datatypes)
end function

public function integer of_setborderstyle (string as_border);is_border = Lower(as_border)

CHOOSE CASE is_border
	CASE 'xp'
		r_1.Visible = TRUE
		THIS.Border = FALSE
	CASE 'lowered'
		r_1.Visible = FALSE
		THIS.Border = TRUE
		THIS.BorderStyle = StyleLowered!
	CASE 'none'
		r_1.Visible = FALSE
		THIS.Border = FALSE
END CHOOSE

//Force a Redraw
of_Resize(THIS.Width - 10, THIS.Height)
of_Resize(THIS.Width, THIS.Height)

RETURN 1
end function

public function integer of_settabwidth (integer ai_tabwidth);RETURN Send(il_SCI, SCI_SETTABWIDTH, ai_tabwidth, 0)
end function

public function integer of_resize (integer al_width, integer al_height);Long ll_findheight = 0
Long ll_pbfindheight = 0,ll_find=0
Integer ll_adjust

IF st_findback.Visible = TRUE THEN
	ll_findheight =  UnitsToPixels(st_findback.Height, YUnitsToPixels!)
	ll_pbfindheight = st_findback.Height
	ll_find  =st_findback.Height
else
	ll_find  =0
END IF

IF dw_2.Visible = TRUE THEN
	ll_pbfindheight = ll_pbfindheight + dw_2.Height + 12
	ll_findheight =  ll_findheight + UnitsToPixels(dw_2.Height + 12, YUnitsToPixels!)
END IF
		
//Scintilla Editor
SetWindowPos(il_SCI, 1, 0, 0, UnitsToPixels(al_width, XUnitsToPixels!),&
								UnitsToPixels(al_height - 18, YUnitsToPixels!) - ll_findheight, 0)
				
//dw_1.Resize(al_width, al_height - ll_pbfindheight - 18 )	
dw_1.Move(0, ll_find )
dw_1.Resize(al_width, st_split.y - ll_find )	

ll_adjust = 0

st_findback.Resize(al_width - 8, st_findback.Height)
//st_findback.Move(4, al_height - st_findback.Height - 8 - ll_adjust)
st_findback.Move(4,   ll_adjust)

//dw_findoutput.Resize(dw_1.Width, dw_findoutput.Height)
//dw_findoutput.Move(dw_1.X, st_findback.Y - dw_findoutput.Height - 2)


//dw_2.Move(dw_1.X,  dw_2.Height - 2 )
dw_2.Move(0,  dw_2.y - 2 )
dw_2.Resize(dw_1.Width, dw_2.Height )

//dw_findoutput.Resize(dw_1.Width, dw_findoutput.Height)
//dw_findoutput.Move(dw_1.X, st_findback.Y - dw_findoutput.Height - 2)

st_split.Move(4, dw_2.y - 15)
st_split.Resize(al_width - 10, st_split.Height)


ddlb_1.Y = st_findback.Y + 12
pb_close.Y = st_findback.Y + 26
pb_prev.Y = st_findback.Y + 26
pb_next.Y = st_findback.Y + 26
cbx_matchcase.Y = st_findback.Y + 22
cbx_output.Y = st_findback.Y + 22
st_find.Y = st_findback.Y + 30
sle_text.Y = st_findback.Y + 14
//
RETURN 1
end function

public function integer of_setfontsize (integer ai_size);RETURN Send(il_SCI, SCI_STYLESETSIZE, STYLE_DEFAULT, ai_size)
end function

public function integer of_setfontbold (boolean ab_bold);IF ab_bold THEN
	RETURN Send(il_SCI, SCI_STYLESETBOLD, STYLE_DEFAULT, 1)
ELSE
	RETURN Send(il_SCI, SCI_STYLESETBOLD, STYLE_DEFAULT, 0)
END IF
end function

public function integer of_setfontitalic (boolean ab_italic);IF ab_italic THEN
	RETURN Send(il_SCI, SCI_STYLESETITALIC, STYLE_DEFAULT, 1)
ELSE
	RETURN Send(il_SCI, SCI_STYLESETITALIC, STYLE_DEFAULT, 0)
END IF
end function

public function integer of_showlinenumbers (boolean ab_show);IF ab_show THEN
	Send(il_SCI, SCI_SETMARGINWIDTHN, 0, 45)
	Send(il_SCI, SCI_STYLESETBACK, STYLE_LINENUMBER, il_margincolor)
	Send(il_SCI, SCI_SETMARGINWIDTHN, 1, 8)
ELSE
	Send(il_SCI, SCI_SETMARGINWIDTHN, 0, 0)
	Send(il_SCI, SCI_STYLESETBACK, STYLE_LINENUMBER, RGB(255,255,255))
	Send(il_SCI, SCI_SETMARGINWIDTHN, 1, 17)
END IF

RETURN 1
end function

public function integer of_saveas ();String ls_path, ls_file

IF GetFileSaveName ( "Select File", ls_path, ls_file, " ", &
   "All Files (*.*),*.*" , "", 40962) <> 1 THEN

	RETURN 0
ELSE
	RETURN of_SaveAs(ls_path)
END IF

end function

public function integer of_saveas (string as_file);String ls_text
Long ll_file

ll_file =  FileOpen(as_file, StreamMode!, Write!, LockWrite!, Replace!)

ls_text = of_GetText()

DO Until Len(ls_text) <= 0
	IF Len(ls_text) <= 32765 THEN
		FileWrite(ll_file, ls_text)
		ls_text = ''
	ELSE
		FileWrite(ll_file, Left(ls_text, 32765))
		ls_text = Right(ls_text, (Len(ls_text) - 32765))
	END IF
LOOP

FileClose(ll_file)

of_SetNotModified()	

is_file = as_file

RETURN 1

end function

public function integer of_save ();IF Len(Trim(is_file)) = 0 THEN
	RETURN of_SaveAs()
ELSE
	RETURN of_SaveAs(is_file)
END IF
end function

public function integer of_printpreview (string as_title, boolean ab_preview);IF ab_preview THEN
	dw_1.Reset()
	dw_1.InsertRow(0)
	dw_1.SetItem(1,1, of_Replace(of_GetText(), '~t', '   '))
	dw_1.SetItem(1,2, as_title)
	dw_1.SetPosition(ToTop!)
	dw_1.Show()
ELSE
	dw_1.Hide()
END IF

RETURN 1
end function

public function integer of_print (string as_title);IF dw_1.Visible = TRUE THEN
	IF Len(Trim(as_title)) > 0 THEN
		dw_1.SetItem(1,2,as_title)
	END IF
	dw_1.Print()
ELSE
	dw_1.Reset()
	dw_1.InsertRow(0)
	dw_1.SetItem(1,1, of_Replace(of_GetText(), '~t', '   '))
	dw_1.SetItem(1,2, as_title)
	dw_1.Print()
END IF

RETURN 1
end function

public function integer of_print ();RETURN of_Print('')
end function

public function integer of_printpreview (boolean ab_preview);RETURN of_PrintPreview('',ab_preview)
end function

public function boolean of_printdialog ();PRINTDLG PrintDlg
DEVMODE DevMode
DEVNAMES DevNames
Long pDevNames, pDevMode
Long ll_return
String ls_pathname, ls_filename

PrintDlg.lStructSize 	= 66
PrintDlg.hWndOwner		= Handle(THIS)
PrintDlg.Flags				= il_flags
PrintDlg.nfrompage		= il_frompage
PrintDlg.ntopage			= il_topage
PrintDlg.ncopies			= il_copies
PrintDlg.nminpage			= 1
PrintDlg.nmaxpage			= 10000

ll_return = PrintDlgA(PrintDlg)

If ll_return = 1 Then

	pDevMode = LocalLock(PrintDlg.hDevMode)
	GetDevMode(DevMode,pDevMode,148) // Lock dynamic memory handle
	LocalUnlock(pDevMode) // Unlock dynamic memory handle

	pDevNames = LocalLock(PrintDlg.hDevNames)
	GetDevNames(DevNames,pDevNames,8) // Lock dynamic memory handle
	LocalUnlock(pDevNames) // Unlock dynamic memory handle
	
	il_flags = PrintDlg.Flags
	il_frompage = PrintDlg.nfrompage
	il_topage = PrintDlg.ntopage
	il_copies	= PrintDlg.ncopies
	
	IF il_copies = 1 THEN // ll_copies are provided by devmode..
		il_copies = DevMode.dmcopies
	END IF
	
	dw_1.Modify("DataWindow.Print.Copies='"+String(il_copies)+"'")
	
	IF of_BitWiseAnd(il_flags, PD_NOSELECTION) = PD_NOSELECTION THEN
		dw_1.Modify("DataWindow.Print.Page.Range=''")
	END IF
	
	IF of_BitWiseAnd(il_flags, PD_PAGENUMS) = PD_PAGENUMS THEN
		dw_1.Modify("DataWindow.Print.Page.Range='" + String (il_frompage) + "-" + String (il_topage) + "'")
	END IF

	// Collate Copies
	IF of_BitWiseAnd(il_flags, PD_COLLATE) = PD_COLLATE THEN
		dw_1.Modify("DataWindow.Print.Collate='Yes'")
	ELSE
		dw_1.Modify("DataWindow.Print.Collate='No'")
	END IF

	// Print to file (must prompt user for filename first)
	IF of_BitWiseAnd(il_flags, PD_PRINTTOFILE) = PD_PRINTTOFILE THEN
		IF GetFileSaveName ("Print to File", ls_pathname, ls_filename, "prn", &
			"Printer Files,*.prn,All Files,*.*") <= 0 THEN
			RETURN FALSE
		ELSE
			dw_1.Modify("DataWindow.Print.FileName='"+String(ls_pathname)+"'")
		END IF
	END IF

	PrintSetPrinter(String(pDevNames + DevNames.wDeviceOffset,"address"))
	RETURN TRUE

END IF	
	
RETURN FALSE

end function

public function integer of_print (boolean ab_dialog);RETURN of_Print('', ab_dialog)
end function

public function integer of_print (string as_title, boolean ab_dialog);IF ab_dialog THEN
	IF NOT of_PrintDialog() THEN
		RETURN 0
	END IF
END IF

RETURN of_Print(as_title)
end function

private function integer of_bitwiseand (long al_value1, long al_value2);Integer		li_Cnt
Long			ll_Result
Boolean		lb_Value1[32], lb_Value2[32]

// Check for nulls
IF IsNull(al_Value1) OR IsNull(al_Value2) THEN
	SetNull(ll_Result)
	RETURN ll_Result
End If

// Get all bits for both values
FOR li_Cnt = 1 TO 32
	lb_Value1[li_Cnt] = of_getbit(al_Value1, li_Cnt)
	lb_Value2[li_Cnt] = of_getbit(al_Value2, li_Cnt)
NEXT

// And them together
FOR li_Cnt = 1 TO 32
	IF lb_Value1[li_Cnt] AND lb_Value2[li_Cnt] THEN
		ll_Result = ll_Result + (2^(li_Cnt - 1))
	END IF
NEXT

RETURN ll_Result
end function

private function boolean of_getbit (long al_decimal, integer ai_bit);Boolean lb_null

//Check parameters
IF IsNull(al_decimal) OR IsNull(ai_bit) THEN
	SetNull(lb_null)
	RETURN lb_null
END IF

//Assumption ai_bit is the nth bit counting right to left with
//the leftmost bit being bit one.
//al_decimal is a binary number as a base 10 long.
IF Int(Mod(al_decimal / (2 ^(ai_bit - 1)), 2)) > 0 THEN
	RETURN TRUE
END IF

RETURN FALSE
end function

private function string of_replace (string as_source, string as_old, string as_new);Long	ll_Start
Long	ll_OldLen
Long	ll_NewLen
String ls_Source

//Get the string lenghts
ll_OldLen = Len(as_Old)
ll_NewLen = Len(as_New)

as_old = Lower(as_old)
ls_source = Lower(as_source)

//Search for the first occurrence of as_Old
ll_Start = Pos(ls_Source, as_Old)

DO WHILE ll_Start > 0
	// replace as_Old with as_New
	as_Source = Replace(as_Source, ll_Start, ll_OldLen, as_New)

	ls_source = Lower(as_source)

	// find the next occurrence of as_Old
	ll_Start = Pos(ls_Source, as_Old, (ll_Start + ll_NewLen))

LOOP

RETURN as_Source
end function

public function integer of_find ();IF Lower(st_find.Text) = 'go to:' THEN
	of_Find(TRUE)
ELSE	
	of_Find(NOT st_findback.Visible)
END IF

RETURN 1
end function

private function integer of_bitwiseor (long al_value1, long al_value2);Integer		li_Cnt
Long			ll_Result
Boolean		lb_Value1[32], lb_Value2[32]

// Check for nulls
IF IsNull(al_Value1) OR IsNull(al_Value2) THEN
	SetNull(ll_Result)
	RETURN ll_Result
END IF

// Get all bits for both values
FOR li_Cnt = 1 TO 32
	lb_Value1[li_Cnt] = of_getbit(al_Value1, li_Cnt)
	lb_Value2[li_Cnt] = of_getbit(al_Value2, li_Cnt)
NEXT

// Or them together
FOR li_Cnt = 1 TO 32
	IF lb_Value1[li_Cnt] OR lb_Value2[li_Cnt] THEN
		ll_Result = ll_Result + (2^(li_Cnt - 1))
	END IF
NEXT

RETURN ll_Result
end function

public function window of_getparentwindow ();PowerObject lpo

lpo = THIS.GetParent()

DO UNTIL lpo.TypeOf() = Window!
	lpo = lpo.GetParent()
LOOP

RETURN lpo
end function

public function string of_gettextatline (long al_line);String ls_text
Long ll_length

al_line = al_line - 1

ll_length = Send(il_SCI, SCI_LINELENGTH, al_line, 0) + 1
ls_text = Space(ll_length)

SendMessageString(il_SCI, SCI_GETLINE, al_line, ls_text)

RETURN ls_text

end function

public function long of_getlinefromposition (long ll_position);RETURN Send(il_SCI, SCI_LINEFROMPOSITION, ll_position, 0) + 1

end function

public function integer of_setcursorposition (long ll_position);Send(il_SCI, SCI_SETSELECTIONSTART, ll_position , 0)
Send(il_SCI, SCI_SETSELECTIONEND, ll_position, 0)

RETURN Send(il_SCI, SCI_SCROLLCARET, ll_position, 0)
end function

public function integer of_goto ();IF Lower(st_find.Text) = 'find:' THEN
	of_Goto(TRUE)
ELSE	
	of_Goto(NOT st_findback.Visible)
END IF

RETURN 1

end function

private function integer of_find (boolean ab_switch);st_findback.Visible = ab_switch
pb_close.Visible = ab_switch
//pb_prev.Visible = ab_switch
//pb_next.Visible = ab_switch
//cbx_matchcase.Visible = ab_switch
//cbx_output.Visible = ab_switch
st_find.Visible = ab_switch
sle_text.Visible = ab_switch
ddlb_1.Visible = ab_switch
st_por .Visible = ab_switch

pb_prev.PictureName = 'back.bmp'
pb_next.PictureName = 'forward.bmp'

st_find.Text = 'Buscar:'

IF ab_switch THEN
	sle_text.SetFocus()
	
//	IF cbx_output.Checked THEN
//		dw_findoutput.Visible = TRUE
//		//st_split.Visible = TRUE
//	ELSE
//		dw_findoutput.Visible = FALSE
//		//st_split.Visible = FALSE
//	END IF
	of_cargar_columnas(dw_1)
ELSE
	//dw_findoutput.Visible = FALSE
	//st_split.Visible = FALSE
END IF

of_Resize(THIS.Width, THIS.Height)

RETURN 1
end function

private function integer of_findnext (string as_text, long al_start, long al_end, long al_flag);Long ll_findpos = 1
Long ll_row
Long ll_currentline

IF Len(Trim(as_text)) = 0 OR IsNull(as_text) THEN
	RETURN 0
END IF

//Set the search flags
Send(il_SCI, SCI_SETSEARCHFLAGS, al_flag, 0)

//Set the direction of search
Send(il_SCI, SCI_SETTARGETSTART, al_start, 0)
Send(il_SCI, SCI_SETTARGETEND, al_end, 0)

//Find the text
ll_findpos = SendMessageString(il_SCI, SCI_SEARCHINTARGET, Len(as_text), as_text)
	
IF(ll_findpos <> -1) THEN
	IF NOT cbx_output.Checked THEN
		of_SetCursorPosition(ll_findpos)
		Send(il_SCI, SCI_SETSELECTIONSTART, ll_findpos , 0)
		Send(il_SCI, SCI_SETSELECTIONEND, ll_findpos + Len(as_text), 0)

	ELSE
		ll_currentline = of_GetCurrentLine()
		
		dw_findoutput.Reset()
		
		DO UNTIL ll_findpos <= 0
			ll_row = dw_findoutput.InsertRow(0)
			
			dw_findoutput.SetItem(ll_row, 1, of_GetLineFromPosition(ll_findpos))
			dw_findoutput.SetItem(ll_row, 2, of_GetTextAtLine(of_GetLineFromPosition(ll_findpos)))
			dw_findoutput.SetItem(ll_row, 3, ll_findpos)
			dw_findoutput.SetItem(ll_row, 4, as_text)
			
			IF al_start < al_end THEN
				Send(il_SCI, SCI_SETTARGETSTART, ll_findpos + Len(as_text), 0)
			ELSE
				Send(il_SCI, SCI_SETTARGETSTART, ll_findpos - Len(as_text), 0)
			END IF
			
			Send(il_SCI, SCI_SETTARGETEND, al_end, 0)
			
			ll_findpos = SendMessageString(il_SCI, SCI_SEARCHINTARGET, Len(as_text), as_text)
		LOOP
		
		of_GotoLine(ll_currentline)
	END IF
END IF

RETURN 1
end function

private function integer of_goto (boolean ab_switch);SetRedraw(FALSE)
cbx_output.Checked = FALSE
of_Find(ab_switch)

cbx_matchcase.Visible = FALSE
cbx_output.Visible = FALSE
pb_next.Visible = FALSE
pb_prev.PictureName = 'forward.bmp'
st_find.Text = 'Go To:'
sle_text.Text = ''

SetRedraw(TRUE)

RETURN 1

end function

public function integer of_open ();String ls_path, ls_file

IF GetFileOpenName ( "Select File", ls_path, ls_file, " ", &
   "Source Files (*.sr*),*.sr*" , "") <> 1 THEN

	RETURN 0
ELSE
	RETURN of_Open(ls_path)
END IF
end function

public function integer of_open (string as_file);String ls_text, ls_read
Long ll_file

ll_file =  FileOpen(as_file, StreamMode!, Read!, LockRead!)

DO Until FileRead(ll_file, ls_read) <= 0
	ls_text = ls_text + ls_read
LOOP

FileClose(ll_file)

of_SetText(ls_text)

is_file = as_file

RETURN 1

end function

public subroutine of_cargar_columnas (datawindow adw);
//s_param_cols ls_struc
//ls_struc = dr
//////ls_struc = Message.PowerObjectParm	
//ddlb_1.additem(ls_struc.col1)
//ddlb_1.additem(ls_struc.col2)
//ddlb_1.additem(ls_struc.col3)
//ddlb_1.additem(ls_struc.col4)
//ddlb_1.additem(ls_struc.col5)
ddlb_1.reset( )
string ls_syntax, ls_cadena, ls_temp
long ld_pos, ld_pos_ini, ld_pos_fin
Integer li_fila
ls_syntax = adw.Describe("DataWindow.Syntax")

/* Recupera el nombre de las columnas */
ld_pos = 1
ls_cadena = ''
li_fila =1
Do While ld_pos > 0
	ld_pos = pos(ls_syntax, 'text', ld_pos)
	If ld_pos > 0 Then
		ld_pos_ini = pos(ls_syntax, 'name=', ld_pos)
		ld_pos_fin = pos(ls_syntax, ' ', ld_pos_ini)
		ls_temp = ls_cadena +' '+ mid(ls_syntax, ld_pos_ini+5, ld_pos_fin - ld_pos_ini - 5 )
		If Right(ls_temp, 2)='_t' Then 	
//			li_fila = dw_1.InsertRow(0)
		
//			dw_1.Object.Columna_name[li_fila] = Trim(Left(ls_temp, Len(ls_temp)-2))
			isa_columna[li_fila]= Trim(Left(ls_temp, Len(ls_temp)-2))
//			ddlb_1.additem(Trim(Left(ls_temp, Len(ls_temp)-2)))	

			//-- las etiquetas
			ld_pos_ini = pos(ls_syntax, 'text="', ld_pos_fin)
			ld_pos_fin = pos(ls_syntax, '"', ld_pos_ini+7)
			
//			dw_1.Object.Columna_text[li_fila] = Trim(mid(ls_syntax, ld_pos_ini+6, ld_pos_fin - ld_pos_ini -6))
			ddlb_1.additem(Trim(mid(ls_syntax, ld_pos_ini+6, ld_pos_fin - ld_pos_ini -6)))
			li_fila ++
		End If
			
		ld_pos = ld_pos_fin
	End If
Loop
ddlb_1.selectitem( 1)
ddlb_1.event selectionchanged(1)
Return


end subroutine

public subroutine of_filtrar (string cadena, string columna);string ls_cad,ls_tipo,ls_col
if cadena = ""  then
		this.dw_1.SetFilter("")
else
		ls_col = this.dw_1.describe(columna+'.name')
		ls_tipo=this.dw_1.describe(ls_col+'.coltype')
		ls_cad = 'Upper(string('+ls_col+')) like "%'+Upper(cadena)+'%" '
		this.dw_1.SetFilter(ls_cad)	
end if
this.dw_1.filter()
end subroutine

public function integer of_getwindow (); PowerObject	lpo_parent
Window lw_window

// loop thru parents until a window is found
lpo_parent = GetParent()
Do While lpo_parent.TypeOf() <> Window! and IsValid(lpo_parent)
	lpo_parent = lpo_parent.GetParent()
Loop

// set return to the window or null if not found
If IsValid (lpo_parent) Then
	lw_window = lpo_parent
Else
	SetNull(lw_window)
End If

iw_parent = lw_window

RETURN 1
end function

public function integer of_getid ();
long ll_data

ll_data = dw_1.object.data[dw_1.getrow(),1]
return ll_data
end function

public subroutine of_resize ();of_resize( this.width,this.height)

end subroutine

on u_cst_gridmain.create
this.dw_2=create dw_2
this.st_por=create st_por
this.dw_1=create dw_1
this.st_categoryname=create st_categoryname
this.ddlb_1=create ddlb_1
this.st_split=create st_split
this.dw_findoutput=create dw_findoutput
this.pb_close=create pb_close
this.pb_prev=create pb_prev
this.pb_next=create pb_next
this.st_1=create st_1
this.st_find=create st_find
this.sle_text=create sle_text
this.cbx_matchcase=create cbx_matchcase
this.st_findback=create st_findback
this.cbx_output=create cbx_output
this.r_1=create r_1
this.Control[]={this.dw_2,&
this.st_por,&
this.dw_1,&
this.st_categoryname,&
this.ddlb_1,&
this.st_split,&
this.dw_findoutput,&
this.pb_close,&
this.pb_prev,&
this.pb_next,&
this.st_1,&
this.st_find,&
this.sle_text,&
this.cbx_matchcase,&
this.st_findback,&
this.cbx_output,&
this.r_1}
end on

on u_cst_gridmain.destroy
destroy(this.dw_2)
destroy(this.st_por)
destroy(this.dw_1)
destroy(this.st_categoryname)
destroy(this.ddlb_1)
destroy(this.st_split)
destroy(this.dw_findoutput)
destroy(this.pb_close)
destroy(this.pb_prev)
destroy(this.pb_next)
destroy(this.st_1)
destroy(this.st_find)
destroy(this.sle_text)
destroy(this.cbx_matchcase)
destroy(this.st_findback)
destroy(this.cbx_output)
destroy(this.r_1)
end on

event constructor;String ls_system32
//this.visible=false
THIS.BackColor = 67108864
st_findback.visible = false
pb_close.visible = false
st_por .Visible= false
string ls_dw ,is_tool,ls_dw2
of_getwindow()

Integer xDummy
xDummy = KillTimer( HANDLE(THIS), 1) 
xDummy = SetTimer(Handle(THIS), 1, 5000, 0)

dw_1.Sort()
dw_1.Event RetrieveEnd(dw_1.RowCount())
dw_1.Event RowFocusChanged(1)

istr_parm         = message.powerobjectparm
ids_datastore    = istr_parm.ads_menu 
iou_powerdock = istr_parm.auo_powerdock
iuo_grillamain = istr_parm.auo_grillamain
ls_dw               = ids_datastore.object.tDwGrid[1]
ls_dw2              = ids_datastore.object.tDwGrid2[1]

if ls_dw ='' or isnull(ls_dw)  then ls_dw ='d_mmenu_grid'
dw_1.dataobject =ls_dw
dw_2.dataobject =ls_dw2
          
dw_1.settransobject( sqlca);
dw_2.settransobject( sqlca);
event post ue_refrescar()

//dw_1.retrieve();commit;	
//
//
////Set Size and Position
//of_Resize(THIS.Width, THIS.Height)
//
////Tab Width
//of_SetTabWidth(3)
//
//
//
////Color Settings
//of_SetColorComments(RGB(0,0,255))
//of_SetColorDataTypes(RGB(128,0,128))
//of_SetColorKeywords(RGB(0,128,0))
//of_SetColorMargin(RGB(185,210,248))
//of_SetColorNumber(RGB(0,0,128))
//of_SetColorOpenString(RGB(255,0,0))
//of_SetColorSelected(RGB(49,106,197))
//of_SetColorString(RGB(128,0,0))
//
////Do Not Show Line Numbers
//of_ShowLineNumbers(FALSE)
//
////Set Focus To The Editor Window
//of_SetFocus()
end event

event destructor;//Close The Scintilla Editor Window
DestroyWindow(il_SCI)
end event

type dw_2 from datawindow within u_cst_gridmain
integer y = 1112
integer width = 3278
integer height = 1920
integer taborder = 30
string title = "none"
boolean livescroll = true
borderstyle borderstyle = stylelowered!
end type

type st_por from statictext within u_cst_gridmain
integer x = 1147
integer y = 40
integer width = 160
integer height = 64
integer textsize = -8
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Arial"
long textcolor = 33554432
long backcolor = 15780518
string text = "Por:"
alignment alignment = right!
boolean focusrectangle = false
end type

type dw_1 from u_dw within u_cst_gridmain
integer y = 144
integer width = 3282
integer height = 948
integer taborder = 50
boolean hscrollbar = true
boolean vscrollbar = true
end type

event constructor;call super::constructor;// load sort service
If this.of_StartService("GridStyle") Then
	iSrv_GridStyle.of_SetStyle(True, True, True, True)

//	iSrv_GridStyle.of_AddAutoWidth("iduser")
//	iSrv_GridStyle.of_AddAutoWidth("id_name")
//	iSrv_GridStyle.of_AddAutoWidth("address")
//	iSrv_GridStyle.of_AddAutoWidth("city")
//	iSrv_GridStyle.of_AddAutoWidth("state")
//	iSrv_GridStyle.of_AddAutoWidth("company_name")
//	

	
End If

// load selectrow service
If this.of_StartService("Select") Then
	iSrv_Select.of_SetSelectStyle("extend")
End If

end event

type st_categoryname from statictext within u_cst_gridmain
boolean visible = false
integer x = 1157
integer y = 128
integer width = 402
integer height = 64
integer textsize = -10
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Arial"
long textcolor = 33554432
long backcolor = 67108864
string text = "none"
boolean focusrectangle = false
end type

type ddlb_1 from dropdownlistbox within u_cst_gridmain
boolean visible = false
integer x = 1307
integer y = 24
integer width = 873
integer height = 712
integer taborder = 40
integer textsize = -8
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Arial"
long textcolor = 33554432
boolean allowedit = true
boolean sorted = false
boolean hscrollbar = true
boolean vscrollbar = true
borderstyle borderstyle = stylelowered!
end type

event selectionchanged;is_columna = isa_columna[index] //this.text(index)

sle_text.text=''
sle_text.setfocus( )


end event

type st_split from statictext within u_cst_gridmain
event mousemove pbm_mousemove
event lbuttonup pbm_lbuttonup
integer y = 1088
integer width = 3278
integer height = 16
integer textsize = -10
integer weight = 700
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Arial"
string pointer = "SizeNS!"
long textcolor = 33554432
long backcolor = 134217856
boolean focusrectangle = false
end type

event mousemove;If Not KeyDown(keyLeftButton!) Then
	Return
End If

IF THIS.Visible = FALSE THEN
	RETURN
END IF

//of_MouseMove(flags, xpos, ypos)

Integer	li_cnt
Integer	li_pointerx, li_pointery
Integer	li_minx, li_maxx, li_miny, li_maxy
Integer	li_prevx
Integer	li_prevwidth
Integer	li_prevheight
Integer	li_prevy
Integer	li_upperbound
Integer 	li_parentx, li_parenty
string	ls_redraw
Integer	li_x, li_y, li_width, li_height

// Always keep the Split Bar on top of other objects.
this.SetPosition(ToTop!)

// Store the Begin Movement information.
If ii_prevpositionx = UNITIALIZED or ii_prevpositiony = UNITIALIZED Then
	ii_prevpositionx = This.X
	ii_prevpositiony = This.Y
End If

// Store the previous placement information.
li_prevx = this.X
li_prevwidth = this.Width
li_prevy = this.Y 
li_prevheight = this.Height

// Get the new position.
li_pointerx = PARENT.PointerX()//of_GetParentWindow().PointerX()
li_pointery = PARENT.PointerY()//of_GetParentWindow().PointerY()

// Calculate the Extreme points the split bars can be moved.
li_miny = 240
li_maxy = PARENT.Height - 240
If li_pointery < li_miny Then
	li_pointery = li_miny
ElseIf li_pointery > li_maxy Then
	li_pointery = li_maxy
End If	

// Change to the "Moving" color.
this.BackColor = il_barmovecolor

	
// Position bar on its new location.
this.Y = li_pointery
// Refresh the Width of the bar.
//this.Height = ii_barwidth

PARENT.SetRedraw(TRUE)	


end event

event lbuttonup;Integer	li_cnt
Integer 	li_deltax, li_deltay
Integer	li_pointerx, li_pointery
Integer	li_minx, li_maxx, li_miny, li_maxy
Integer	li_x, li_y, li_width, li_height

this.SetPosition(ToTop!)

// Change to the base color.
this.BackColor = il_barcolor

// Validate that the bar has been moved.
If ii_prevpositionx = UNITIALIZED Or ii_prevpositiony = UNITIALIZED Then
	Return 0
End If

// Get the new position.
li_pointerx = THIS.X
li_pointery = THIS.Y

// Minimize size rounding problems.
//of_UpdateObjectData()

// Position bar on its new location.
this.Y = li_pointery
// Refresh the Width of the bar.
//this.Height = 8
this.Height = 15

//dw_findoutput.Resize(THIS.Width - 10, st_findback.Y - THIS.Y - 16)
//dw_findoutput.Move(4, st_findback.Y - dw_findoutput.Height - 8)

//dw_2.Resize(THIS.Width - 10,  st_findback - THIS.Y - 16)
//dw_2.Move(4, THIS.Y ) //dw_1.Height )
//dw_2.Resize(THIS.Width - 10,  THIS.Y - 16)
dw_2.Move(0,  st_split.y + 15 )

of_resize()
//of_Find(TRUE)

// Reset the Previous position variables to UNITIALIZED.
ii_prevpositionx = UNITIALIZED
ii_prevpositiony = UNITIALIZED
end event

type dw_findoutput from datawindow within u_cst_gridmain
boolean visible = false
integer x = 18
integer y = 480
integer width = 238
integer height = 140
integer taborder = 20
string title = "none"
boolean hscrollbar = true
boolean vscrollbar = true
boolean border = false
boolean livescroll = true
borderstyle borderstyle = stylelowered!
end type

event doubleclicked;of_SetCursorPosition(GetItemNumber(row, 'cursor_position'))
Send(il_SCI, SCI_SETSELECTIONSTART, GetItemNumber(row, 'cursor_position') , 0)
Send(il_SCI, SCI_SETSELECTIONEND, GetItemNumber(row, 'cursor_position') + Len(GetItemString(row, 'search_string')), 0)

SelectRow(0, FALSE)
SelectRow(row, TRUE)
end event

event clicked;SelectRow(0, FALSE)
SelectRow(row, TRUE)
end event

event constructor;//THIS.Create('release 9; ' + &
//'datawindow(units=0 timer_interval=0 color=1073741824 processing=0 HTMLDW=no print.printername="" print.documentname="" print.orientation = 0 print.margin.left = 110 print.margin.right = 110 print.margin.top = 96 print.margin.bottom = 96 print.paper.source = 0 print.paper.size = 0 print.canusedefaultprinter=yes print.prompt=no print.buttons=no print.preview.buttons=no print.cliptext=no print.overrideprintjob=no print.collate=yes hidegrayline=no ) ' + &
//'summary(height=0 color="536870912" ) ' + &
//'footer(height=0 color="536870912" ) ' + &
//'detail(height=56 color="536870912" ) ' + &
//'table(column=(type=long updatewhereclause=no name=line dbname="line" ) ' + &
//' column=(type=char(255) updatewhereclause=no name=syntax dbname="syntax" ) ' + &
//' column=(type=long updatewhereclause=no name=cursor_position dbname="cursor_position" ) ' + &
//' column=(type=char(255) updatewhereclause=no name=search_string dbname="search_string" ) ' + &
//' ) ' + &
//'column(band=detail id=1 alignment="1" tabsequence=32766 border="0" color="33554432" x="5" y="0" height="56" width="160" format="[general]" html.valueishtml="0"  name=line visible="1" edit.limit=0 edit.case=any edit.autoselect=yes edit.autohscroll=yes edit.imemode=0  font.face="Arial" font.height="-8" font.weight="400"  font.family="2" font.pitch="2" font.charset="0" background.mode="1" background.color="536870912" ) ' + &
//'column(band=detail id=2 alignment="0" tabsequence=32766 border="0" color="33554432" x="187" y="0" height="56" width="3543" format="[general]" html.valueishtml="0"  name=syntax visible="1" edit.limit=0 edit.case=any edit.autoselect=yes edit.autohscroll=yes edit.imemode=0  font.face="Arial" font.height="-8" font.weight="400"  font.family="2" font.pitch="2" font.charset="0" background.mode="1" background.color="536870912" )')
end event

type pb_close from picture within u_cst_gridmain
integer x = 37
integer y = 36
integer width = 78
integer height = 68
string picturename = "..\\IMG\ICO\Cancel.png"
boolean focusrectangle = false
end type

event clicked;of_Find(FALSE)
end event

type pb_prev from picture within u_cst_gridmain
event lbuttondown pbm_lbuttondown
event lbuttonup pbm_lbuttonup
boolean visible = false
integer x = 1161
integer y = 40
integer width = 78
integer height = 68
boolean originalsize = true
string picturename = "back.bmp"
borderstyle borderstyle = styleraised!
boolean focusrectangle = false
end type

event lbuttondown;SetCapture(Handle(THIS))

IF Lower(st_find.Text) = 'find:' THEN
	THIS.PictureName = 'backpressed.bmp'
ELSE
	THIS.PictureName = 'forwardpressed.bmp'
END IF

end event

event lbuttonup;ReleaseCapture()

Long ll_flag, ll_start

IF Lower(st_find.Text) = 'find:' THEN
	IF cbx_matchcase.Checked THEN
		ll_flag = SCFIND_MATCHCASE
	END IF
	
	ll_start = Send(il_SCI, SCI_GETCURRENTPOS, 0, 0) - Len(sle_text.Text)
	
	of_FindNext(sle_text.Text, ll_start, 0, ll_flag)

	THIS.PictureName = 'back.bmp'
ELSE
	
	IF IsNumber(sle_text.Text) THEN
		of_GotoLine(Long(sle_text.Text))
	END IF
	
	THIS.PictureName = 'forward.bmp'
END IF

end event

event doubleclicked;SetCapture(Handle(THIS))

IF Lower(st_find.Text) = 'find:' THEN
	THIS.PictureName = 'backpressed.bmp'
ELSE
	THIS.PictureName = 'forwardpressed.bmp'
END IF

end event

type pb_next from picture within u_cst_gridmain
event lbuttondown pbm_lbuttondown
event lbuttonup pbm_lbuttonup
boolean visible = false
integer x = 1280
integer y = 40
integer width = 78
integer height = 68
boolean originalsize = true
string picturename = "forward.bmp"
boolean focusrectangle = false
end type

event lbuttondown;SetCapture(Handle(THIS))
THIS.PictureName = 'forwardpressed.bmp'
end event

event lbuttonup;ReleaseCapture()

Long ll_flag, ll_start, ll_end

IF cbx_matchcase.Checked THEN
	ll_flag = SCFIND_MATCHCASE
END IF

ll_start = Send(il_SCI, SCI_GETCURRENTPOS, 0, 0)
ll_end = Send(il_SCI, SCI_GETTEXTLENGTH, 0, 0) + 1

of_FindNext(sle_text.Text, ll_start, ll_end, ll_flag)

THIS.PictureName = 'forward.bmp'
end event

event doubleclicked;SetCapture(Handle(THIS))
THIS.PictureName = 'forwardpressed.bmp'
end event

type st_1 from statictext within u_cst_gridmain
integer x = 142
integer y = 824
integer width = 805
integer height = 60
integer textsize = -10
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Arial"
long textcolor = 16777215
long backcolor = 8421376
string text = "PB Syntax Editor Control v2.0"
end type

event constructor;THIS.Visible = FALSE
end event

type st_find from statictext within u_cst_gridmain
boolean visible = false
integer x = 146
integer y = 36
integer width = 224
integer height = 64
integer textsize = -8
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Arial"
long textcolor = 33554432
long backcolor = 15780518
string text = "Buscar:"
alignment alignment = right!
boolean focusrectangle = false
end type

type sle_text from singlelineedit within u_cst_gridmain
event enchange pbm_enchange
boolean visible = false
integer x = 361
integer y = 28
integer width = 782
integer height = 88
integer taborder = 30
integer textsize = -8
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Arial"
long textcolor = 33554432
borderstyle borderstyle = stylelowered!
end type

event enchange;Long ll_flag, ll_start, ll_end

IF NOT cbx_output.Checked THEN
	
	IF cbx_matchcase.Checked THEN
		ll_flag = SCFIND_MATCHCASE
	END IF
	
	ll_start = Send(il_SCI, SCI_GETCURRENTPOS, 0, 0) - Len(THIS.Text) - 1
	ll_end = Send(il_SCI, SCI_GETTEXTLENGTH, 0, 0) + 1
	of_filtrar(THIS.Text,is_columna)
//	of_FindNext(THIS.Text, ll_start, ll_end, ll_flag)
	
	
END IF
end event

type cbx_matchcase from checkbox within u_cst_gridmain
boolean visible = false
integer x = 1399
integer y = 36
integer width = 384
integer height = 76
integer textsize = -9
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Arial"
long textcolor = 33554432
long backcolor = 67108864
string text = "Match Case"
end type

type st_findback from statictext within u_cst_gridmain
boolean visible = false
integer y = 4
integer width = 3287
integer height = 140
integer textsize = -10
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Arial"
long textcolor = 33554432
long backcolor = 15780518
alignment alignment = center!
boolean border = true
boolean focusrectangle = false
end type

type cbx_output from checkbox within u_cst_gridmain
boolean visible = false
integer x = 1742
integer y = 32
integer width = 270
integer height = 76
boolean bringtotop = true
integer textsize = -10
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Arial"
long textcolor = 33554432
long backcolor = 67108864
string text = "Output"
end type

event clicked;of_Find(TRUE)
end event

type r_1 from rectangle within u_cst_gridmain
integer linethickness = 4
long fillcolor = 67108864
end type

event constructor;THIS.LineColor = RGB(127,157,185)
end event

